package com.like.banzipao.server.plugins

import com.like.banzipao.server.exception.InvalidCredentialsException
import com.like.banzipao.server.respondError
import io.ktor.http.HttpStatusCode
import io.ktor.server.application.Application
import io.ktor.server.application.install
import io.ktor.server.plugins.statuspages.StatusPages

fun Application.configureStatusPages() {
    // 安装状态页特性
    install(StatusPages) {
        // 注册这个异常类型
        exception<InvalidCredentialsException> { call, cause ->
            // 生成一个未授权（Unauthorized）页
            call.respondError(cause.message, HttpStatusCode.Unauthorized.value)
        }
    }
}
